home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / test / lib / cexec.c < prev    next >
C/C++ Source or Header  |  1992-11-23  |  1KB  |  62 lines

  1.  
  2. /*
  3.  *  CEXEC.C
  4.  *
  5.  *  test exec capability
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <exec/ports.h>
  10. #include <libraries/dos.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13.  
  14. typedef struct MsgPort    MsgPort;
  15. typedef struct Message    Message;
  16.  
  17. main(ac, av)
  18. char *av[];
  19. {
  20.     char *resName;
  21.     long resNode;
  22.     MsgPort *port;
  23.     Message *msg;
  24.     char buf[256];
  25.     int r;
  26.  
  27.     if (ac == 1) {
  28.     puts("cexec program");
  29.     exit(1);
  30.     }
  31.     port = CreatePort(NULL, 0);
  32.     resNode = MakeResidentNode(port, &resName);
  33.  
  34.     printf("resNode %08lx name %s\n", resNode, resName);
  35.     sprintf(buf, "%s %s", resName, av[1]);
  36.     puts(buf);
  37.     r = Execute(buf, NULL, NULL);
  38.     printf("r = %d\n", r);
  39.     if (r) {
  40.     puts("waiting for message...");
  41.     while ((msg = GetMsg(port)) == NULL) {
  42.         long m = Wait (SIGBREAKF_CTRL_C | (1 << port->mp_SigBit));
  43.         if (m & SIGBREAKF_CTRL_C) {
  44.         puts("break-abort");
  45.         break;
  46.         }
  47.     }
  48.     if (msg) {
  49.         printf("msg, return code: %d\n", msg->mn_Node.ln_Name);
  50.         FreeMem(msg, msg->mn_Length);
  51.     }
  52.     }
  53.     puts("unloading in 2 secs");
  54.     Delay(50*2);
  55.     puts("unloading...");
  56.     r = DeleteResidentNode(resNode);
  57.     if (r < 0)
  58.     puts("wasn't able to find node!");
  59.     DeletePort(port);
  60. }
  61.  
  62.